package com.stellar.circle.controller.admin.sIdle;

import com.stellar.circle.controller.admin.sIdle.vo.SIdleRequestPageVO;
import com.stellar.circle.controller.admin.sIdle.vo.SIdleRequestVO;
import com.stellar.circle.controller.admin.sIdle.vo.SIdleResponseVO;
import com.stellar.circle.domain.sIdle.SIdleDomainService;
import com.stellar.web.core.bean.PageResult;
import com.stellar.web.core.bean.Result;
import com.stellar.web.core.constants.AuthUserConstants;
import com.stellar.web.core.validator.ValidatorRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 闲置物品交易表控制器
 *
 * @author Jqchan
 * @version 1.0
 * @date 2025-06-07 20:13:37
 */
@RequestMapping("/api-admin/sIdle")
@RestController("adminSIdleController")
@Slf4j
public class SIdleController {

    @Resource
    private SIdleDomainService sIdleDomainService;

    /**
     * 分页查询闲置物品交易表
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @PostMapping("/page")
    public Result<PageResult<SIdleResponseVO>> page(@RequestBody SIdleRequestPageVO requestPageVO) {
        return Result.success(sIdleDomainService.page(requestPageVO));
    }

    /**
     * 新增闲置物品交易表
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @PostMapping("/create")
    public Result<Boolean> create(@RequestBody SIdleRequestVO requestVO) {
        return Result.success(sIdleDomainService.insert(requestVO));
    }

    /**
     * 修改闲置物品交易表
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody SIdleRequestVO requestVO) {
        return Result.success(sIdleDomainService.update(requestVO));
    }

    /**
     * 删除闲置物品交易表
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        return Result.success(sIdleDomainService.delete(id));
    }

    /**
     * 获取闲置物品交易表详情
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @GetMapping("/get/{id}")
    public Result<SIdleResponseVO> get(@PathVariable("id") Long id) {
        return Result.success(sIdleDomainService.get(id));
    }

    /**
     * 完成交易
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @PostMapping("/complete")
    public Result<Boolean> complete(@RequestParam Long id) {
        return Result.success(sIdleDomainService.complete(id));
    }

    /**
     * 关闭交易
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN})
    @PostMapping("/close")
    public Result<Boolean> close(@RequestParam Long id) {
        return Result.success(sIdleDomainService.close(id));
    }
}
